//
//  GNNavController.swift
//  SinaWeChat
//
//  Created by mac on 15/12/5.
//  Copyright © 2015年 mac. All rights reserved.
//

import UIKit

class GNNavController: UINavigationController,UIGestureRecognizerDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        
        self.interactivePopGestureRecognizer?.delegate = self
    }

    override func pushViewController(viewController: UIViewController, animated: Bool) {
        
        //更改左上角的返回按钮
        
        // 如果当前导航控制器里面有1个子控制器,那么执行到这个地方的时候,就代表
        // 将要push进来第2个,把 push 进来 的控制器的左边按钮改成第一个控制器的title
        
        //判断内部有几个控制器,执行不同的逻辑
        
        if childViewControllers.count != 0{
            
            var title:String = "返回"
            
            if childViewControllers.count == 1{
                
                
                title = childViewControllers.first!.title ?? title
                
            }
            
            //判断如果当前的是rootViewController就不设置
            
            viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(imgName: "navigationbar_back_withtext", title: title, target: self, action: "back")
            
            
            //隐藏底部的tabBar
            
            viewController.hidesBottomBarWhenPushed = true
            
            
            
            
            
        }
        
        super.pushViewController(viewController, animated: true)
        
        
    }
    
    
    
    @objc private func back(){
        
        
        popViewControllerAnimated(true)
        
    }
    
    //MARK: - gesture delegate
    
    func gestureRecongnizeShouldBegin(gestureRecognizer: UIGestureRecognizer) ->Bool{
        
        print("拖动中")
        
        return childViewControllers.count != 1
    }
    

    

}
